package com.yl.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public enum TimeUnit {

    S("s", "秒", 1),
    M("m", "分", 60),
    H("h", "时", 60 * 60),
    D("d", "日", 24 * 60 * 60);

    private String tag;
    private String desc;
    private Integer ratio;

    /**
     * 根据时间单位简写获取对象
     */
    public static TimeUnit get(String containTagStr) {
        for (TimeUnit timeUnit : TimeUnit.values()) {
            if (containTagStr.contains(timeUnit.getTag())) {
                return timeUnit;
            }
        }
        return null;
    }

}

